def isPrime(d):
    if d == 1: return False
    test = True
    k = d - 1
    while k > 1:
        if not d % k:
            test = False
            break
        k -= 1
    return test

h = input()
s=[]
for i in range(len(h)):
    for k in range(i + 1,len(h) +1):
        a = int(h[i:k])
        if isPrime(a):
            s += [a]
print  (max(s) if s else 0)
